package ph.greenova.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import ph.greenova.web.dto.PersonDTO;

/**
 * Created By: adrian
 * Date Created: 6:32 AM 6/5/13
 */
@Controller
@RequestMapping(value = "persons")
public class PersonController extends BaseController{


    @RequestMapping(value = "create", method = RequestMethod.GET)
    public ModelAndView viewCreatePerson(final ModelMap model) {

        model.addAttribute("personForm",new PersonDTO());
        return new ModelAndView("viewCreatePerson",model);
    }

    @RequestMapping(value = "create", method = RequestMethod.POST)
    public String createPerson(@ModelAttribute("personForm")final PersonDTO dto, final ModelMap model) {
        getPersonService().createNewPerson(dto);
        return "redirect:/projects";
    }
}
